//
//  UIView+ADUtil.h
//  ADKit
//
//  Created by duzexu on 2017/12/1.
//  Copyright © 2017年 duzexu. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIView (ADUtil)

//nib loading

+ (instancetype)ad_instanceWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)bundleOrNil owner:(id)owner;
+ (instancetype)ad_instanceFromNib;
- (void)ad_loadContentsWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)bundleOrNil;

//hierarchy

- (UIView *)ad_viewMatchingPredicate:(NSPredicate *)predicate;
- (UIView *)ad_viewWithTag:(NSInteger)tag ofClass:(Class)viewClass;
- (UIView *)ad_viewOfClass:(Class)viewClass;
- (NSArray *)ad_viewsMatchingPredicate:(NSPredicate *)predicate;
- (NSArray *)ad_viewsWithTag:(NSInteger)tag;
- (NSArray *)ad_viewsWithTag:(NSInteger)tag ofClass:(Class)viewClass;
- (NSArray *)ad_viewsOfClass:(Class)viewClass;

- (UIView *)ad_firstSuperviewMatchingPredicate:(NSPredicate *)predicate;
- (UIView *)ad_firstSuperviewOfClass:(Class)viewClass;
- (UIView *)ad_firstSuperviewWithTag:(NSInteger)tag;
- (UIView *)ad_firstSuperviewWithTag:(NSInteger)tag ofClass:(Class)viewClass;

- (BOOL)ad_viewOrAnySuperviewMatchesPredicate:(NSPredicate *)predicate;
- (BOOL)ad_viewOrAnySuperviewIsKindOfClass:(Class)viewClass;
- (BOOL)ad_isSuperviewOfView:(UIView *)view;
- (BOOL)ad_isSubviewOfView:(UIView *)view;

- (UIViewController *)ad_firstViewController;
- (UIView *)ad_firstResponder;

//frame accessors

@property (nonatomic, assign) CGPoint ad_origin;
@property (nonatomic, assign) CGSize ad_size;
@property (nonatomic, assign) CGFloat ad_top;
@property (nonatomic, assign) CGFloat ad_left;
@property (nonatomic, assign) CGFloat ad_bottom;
@property (nonatomic, assign) CGFloat ad_right;
@property (nonatomic, assign) CGFloat ad_width;
@property (nonatomic, assign) CGFloat ad_height;
@property (nonatomic, assign) CGFloat ad_centerX;
@property (nonatomic, assign) CGFloat ad_centerY;

@property (nonatomic, readonly) CGFloat ad_screenX;
@property (nonatomic, readonly) CGFloat ad_screenY;
@property (nonatomic, readonly) CGRect ad_screenFrame;

//bounds accessors

@property (nonatomic, assign) CGSize ad_boundsSize;
@property (nonatomic, assign) CGFloat ad_boundsWidth;
@property (nonatomic, assign) CGFloat ad_boundsHeight;

//content getters

@property (nonatomic, readonly) CGRect ad_contentBounds;
@property (nonatomic, readonly) CGPoint ad_contentCenter;

- (void)ad_removeAllSubviews;

/**
 Attaches the given block for a single tap action to the receiver.
 @param block The block to execute.
 */
- (void)ad_setTapActionWithBlock:(void (^)(void))block;
- (void)ad_setTapActionWithGestureBlock:(void (^)(UITapGestureRecognizer *gesture))block;
- (void)ad_setNoImpactTapActionWithBlock:(void (^)(void))block;
- (void)ad_setTapActionWithFrame:(CGRect)frame block:(void (^)(void))block;

/**
 Attaches the given block for a long press action to the receiver.
 @param block The block to execute.
 */
- (void)ad_setLongPressActionWithBlock:(void (^)(void))block;

/**
 * view add shadow
 */
- (UIView *)ad_addStanderdShadow;

/**
 * view add or remove red dot
 */
- (UIView *)ad_unreadDot:(BOOL)add offset:(CGPoint)offect;

/**
 * view add cornerRadius in some corners
 */
- (UIView *)ad_addCornerRadius:(CGFloat)cornerRadius corners:(UIRectCorner)corners;

@end

@interface UIView (ADIBnspectable)

@property (assign,nonatomic) IBInspectable CGFloat cornerRadius;
@property (assign,nonatomic) IBInspectable CGFloat borderWidth;
@property (assign,nonatomic) IBInspectable BOOL    masksToBounds;
// set border hex color
@property (strong,nonatomic) IBInspectable NSString  *borderHexRgb;
@property (strong,nonatomic) IBInspectable UIColor   *borderColor;
// set background hex color
@property (assign,nonatomic) IBInspectable NSString  *hexRgbColor;

@property (assign,nonatomic) IBInspectable BOOL      onePx;

@end

